// 后台资产页中的用户资金账户列表
// import { isEmpty } from 'lodash'
import * as types from '@/store/mutation-types'
import api from '@/tools/api.js'
import promise from '@/tools/promise'
// import { SUCCESS_STATUS } from '@/config/status'
const state = {
  list: [],
  pageData: {
    total: 1,
    per_page: 15,
    current_page: 1,
    last_page: 1
  },
  saveData: {}
}

// mutations
const mutations = {
  [types.FUND_ACCOUNT_LIST] (state, payload) {
    state.list = payload.data
    state.pageData.total = Number(payload.total)
    state.pageData.per_page = Number(payload.per_page)
    state.pageData.current_page = Number(payload.current_page)
    state.pageData.last_page = Number(payload.last_page)
  },
  [types.FUND_SAVE_DATA] (state, payload) {
    state.saveData = payload
  }
}

// actions
const actions = {
  // 获取资金账户列表
  async getFundAccountList ({ commit }, payload) {
    let config = {loading: true, loadingText: '正在获取资金账户列表'}
    let getRes = await api('serverfund/fund/FundAccount/list', payload, config)
    commit(types.FUND_ACCOUNT_LIST, getRes.res)
  },
  // 资金冻结
  async fundFreeze ({ commit }, payload) {
    let config = {loading: true, loadingText: '正在冻结资金'}
    let res = await api('serverfund/fund/FundAccount/freeze', payload, config)
    return promise(res)
  },
  // 资金充值
  async fundRecharge ({ commit }, payload) {
    let config = {loading: true, loadingText: '正在充值资金'}
    let res = await api('serverfund/fund/FundAccount/prepaid', payload, config)
    return promise(res)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
